home *** CD-ROM | disk | FTP | other *** search
- --------------------------------------------------------------------------------
- -- Weapon Mosquito + Projectile Mosquito
- -- Original Carnage Contest Weapon
- -- Script by DC, December 2009, www.UnrealSoftware.de
- --------------------------------------------------------------------------------
-
- -- Setup Tables
- if cc==nil then cc={} end
- cc.mosquito={}
- cc.mosquito.mosquito={}
-
- -- Load & Prepare Ressources
- cc.mosquito.gfx_wpn0=loadgfx("weapons/mosquito0.bmp") -- Weapon Image Frame 0
- setmidhandle(cc.mosquito.gfx_wpn0)
- cc.mosquito.gfx_wpn1=loadgfx("weapons/mosquito1.bmp") -- Weapon Image Frame 1
- setmidhandle(cc.mosquito.gfx_wpn1)
- cc.mosquito.sfx_attack=loadsfx("mosquito.ogg") -- Attack Sound
-
- --------------------------------------------------------------------------------
- -- Weapon: Mosquito
- --------------------------------------------------------------------------------
-
- cc.mosquito.id=addweapon("cc.mosquito","Mosquito",cc.mosquito.gfx_wpn0,0,2) -- Add Weapon (0 uses, first in round 2)
-
- function cc.mosquito.draw() -- Draw
- -- Animation
- weapon_timer=weapon_timer+1
- if weapon_timer>4 then
- weapon_timer=0
- weapon_mode=1-weapon_mode
- end
- -- Draw
- if weapon_shots==0 then
- setblend(blend_alpha)
- setalpha(1)
- setcolor(255,255,255)
- if weapon_mode==0 then
- drawinhand(cc.mosquito.gfx_wpn0,6,0)
- else
- drawinhand(cc.mosquito.gfx_wpn1,6,0)
- end
- -- HUD Crosshair
- hudcrosshair(6,3)
- end
- end
-
- function cc.mosquito.attack(attack) -- Attack
- if (weapon_shots<=0) then
- -- Fire a projectile (on release/full charge)
- if (attack==1) then
- -- No more weapon switching!
- useweapon(0)
- -- Disable player control
- playercontrol(0)
- -- Make sure that there is enough round time
- secondsleft=math.floor(getframesleft()/50)
- changeturntime(30-secondsleft)
- -- Launch
- weapon_shots=weapon_shots+1
- id=createprojectile(cc.mosquito.mosquito.id)
- projectiles[id]={}
- -- Ignore collision with current player at beginning
- projectiles[id].ignore=playercurrent()
- -- Set initial position of projectile
- projectiles[id].x=getplayerx(0)+(6*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*3.0
- projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*3.0
- -- Set speed of projectile
- projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*3.0
- projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*3.0
- -- Set timer
- projectiles[id].timer=30*50
- -- Effects
- recoil(2)
- end
- end
- end
-
- --------------------------------------------------------------------------------
- -- Projectile: Mosquito
- --------------------------------------------------------------------------------
-
- cc.mosquito.mosquito.id=addprojectile("cc.mosquito.mosquito") -- Add Projectile
-
- function cc.mosquito.mosquito.draw(id) -- Draw
- -- Setup draw mode
- setblend(blend_alpha)
- setalpha(1)
- setcolor(255,255,255)
- setscale(1,1)
- -- Calculate projectile rotation
- setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
- -- Draw projectile
- if weapon_mode==0 then
- drawimage(cc.mosquito.gfx_wpn0,projectiles[id].x,projectiles[id].y)
- else
- drawimage(cc.mosquito.gfx_wpn1,projectiles[id].x,projectiles[id].y)
- end
- -- Draw Arrow if out of Screen
- outofscreenarrow(projectiles[id].x,projectiles[id].y)
- -- Sound
- if channelplaying(0)==0 then playsound(cc.mosquito.sfx_attack,0) end
- end
-
- function cc.mosquito.mosquito.update(id) -- Update
- -- Control by player
- rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
- if keydown(key_left)==1 then
- rot=rot-5
- elseif keydown(key_right)==1 then
- rot=rot+5
- end
- projectiles[id].sx=math.sin(math.rad(rot))*3.0
- projectiles[id].sy=-math.cos(math.rad(rot))*3.0
- -- Wind influence on speed
- projectiles[id].sx=projectiles[id].sx+getwind()*0.5
- -- Move (in substep loop for optimal collision precision)
- msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
- msubx=projectiles[id].sx/msubt
- msuby=projectiles[id].sy/msubt
- for i=1,msubt,1 do
- projectiles[id].x=projectiles[id].x+msubx
- projectiles[id].y=projectiles[id].y+msuby
- -- Collision
- if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*3,projectiles[id].y-math.cos(math.rad(rot))*3)==1 then
- if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
- projectiles[id].timer=0
- if playercollision()>0 and playercollision()~=projectiles[id].ignore then
- -- Intoxicate
- playerstate(playercollision(),state_poisoned,1)
- -- Damage
- playerdamage(playercollision(),5)
- end
- break
- end
- else
- projectiles[id].ignore=0
- end
- -- Water
- if (projectiles[id].y)>getwatery()-30 then
- -- Stop SFX Loop
- stopchannel(0)
- -- Effects
- particle(p_waterhit,projectiles[id].x,projectiles[id].y)
- playsound(sfx_hitwater3)
- -- Free projectile
- freeprojectile(id)
- -- End Turn
- endturn()
- break
- end
- end
- -- Timer / Explode
- projectiles[id].timer=projectiles[id].timer-1
- if projectiles[id].timer<=0 then
- -- Stop SFX Loop
- stopchannel(0)
- -- Splatter
- playsound(sfx_splatter2)
- -- Green Insect Stuff
- if math.random(0,1)==1 then
- terrainalphaimage(gfx_blood25,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,0,math.random(200,250),0)
- else
- terrainalphaimage(gfx_blood50,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,0,math.random(200,250),0)
- end
- particle(p_smoke,projectiles[id].x,projectiles[id].y)
- particlealpha(1.0)
- particlecolor(0,255,0)
- particlesize(20,20)
- particlefadealpha(0.009)
- for i=1,5,1 do
- particle(p_blood,projectiles[id].x,projectiles[id].y)
- particlecolor(0,255,0)
- end
- -- Free projectile
- freeprojectile(id)
- -- End Turn
- endturn()
- end
- -- Scroll to projectile
- scroll(projectiles[id].x,projectiles[id].y)
- end